import Page
from Page import Yomi
from Base.Base import Base
from selenium.webdriver.common.by import By


class YomiMusicPage(Base):
    """
    语音训练导航音乐页

    """

    def __init__(self, driver):
        Base.__init__(self, driver)

        # 左侧的home键
        self.music_home_btn = (By.XPATH, Yomi.RESOURCE_ID_Music.format("ivHome"))

        # 左侧的返回键
        self.music_back_btn = (By.XPATH, Yomi.RESOURCE_ID_Music.format('ivBack'))

        # 选择音乐标题
        self.music_title_text = (By.XPATH, Yomi.music_title_text.format(""))

        # 语音搜索
        self.music_voice_btn = (By.XPATH, Yomi.RESOURCE_ID_Music.format("bt_voice"))

        # 节目输入
        self.music_program_input = (By.XPATH, Yomi.RESOURCE_ID_Music.format("et_music"))

        # 立即搜索
        self.music_now_search_btn = (By.XPATH, Yomi.RESOURCE_ID_Music.format("btn_search"))

        # 删除按钮
        self.music_delete_btn = (By.XPATH, Yomi.RESOURCE_ID_Music.format("iv_delete"))

        # 搜索历史标题
        self.music_search_history_title_text = (By.XPATH, Yomi.RESOURCE_ID_Music.format("tv_search_result_title"))

        # 搜索历史
        self.music_search_history_text = (By.XPATH, Yomi.search_result_text.format(""))

    def click_back(self):
        """
        点击左侧的back键

        :return:None
        """
        self.click_element(self.music_back_btn)

    def click_home(self):
        """
        点击左侧的home键

        :return:None
        """
        self.click_element(self.music_home_btn)

    def click_delete(self):
        """
        点击删除按钮

        :return:None
        """
        self.click_element(self.music_delete_btn)

    def get_title(self, index=1):
        """
        获取音乐标题

        :return:获取元素
        """
        self.music_title_text = (By.XPATH, Yomi.music_title_text.format(index))
        return self.find_element_o(self.music_title_text)

    def click_voice(self):
        """
        点击语音搜索按钮

        :return:None
        """
        self.click_element(self.music_voice_btn)

    def input_program(self, index):
        """
        节目输入

        index 为输入的节目
        :return:None
        """
        self.input_text(self.music_program_input, index)

    def click_now_search(self):
        """
        点击立即搜索

        :return:None
        """
        self.click_element(self.music_now_search_btn)

    def get_search_history_title(self):
        """
        获取搜索历史标题

        :return:获取元素
        """
        return self.find_element_o(self.music_search_history_title_text)

    def get_program(self):
        """
        获取音乐输入内容

        :return:获取元素
        """
        return self.find_element_o(self.music_program_input)

    def get_search_history(self, index=1):
        """
        获取搜索结果

        :return:获取元素
        """
        self.music_search_history_text = (By.XPATH, Yomi.search_result_text.format(index))
        return self.find_element_o(self.music_search_history_text)

    def swipe_radio_online_list(self):
        """
        滑动城市列表

        :return:None
        """
        self.swipe_o(location=(952, 952, 438, 640), direction='up')

    def is_display_yomi_music(self):
        """
        查看是否进入语音训练在线电台
        :return:
        """
        return self.is_display(self.music_voice_btn)
